package com.emep.changzhi.analyse.service.basics;

import com.emep.changzhi.analyse.entity.basics.SysEmissionStandardTotalInfo;
import com.emep.changzhi.analyse.repository.basics.SysEmissionStandardTotalInfoRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Wangcc
 * @version V1.0
 * @Description: 排放标准总则业务层
 * @date 2018/2/26 15:24
 */
@Service
public class SysEmissionStandardTotalInfoService {
    
    @Resource
    private SysEmissionStandardTotalInfoRepository sysEmissionStandardTotalInfoRepository;

    private static final Logger logger = LoggerFactory.getLogger(SysEmissionStandardTotalInfoService.class);


    /**
     *
     * 不含查询条件的分页获取数据
     *
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     */
    public Page<SysEmissionStandardTotalInfo> findAll(Integer pageNo, Integer pageSize){
        try {
            Pageable pageable = new PageRequest(pageNo-1, pageSize);
            return  sysEmissionStandardTotalInfoRepository.findAll(pageable);
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage());
            return null;
        }
    }

    /**
     *
     * 新增排放标准总则
     *
     * @param payload
     * @return
     * @throws Exception
     */
    public SysEmissionStandardTotalInfo save(Map<String, Object> payload) {
        SysEmissionStandardTotalInfo SysEmissionStandardTotalInfo = null;
        try {
            SysEmissionStandardTotalInfo SysEmissionStandardTotalInfo1 = (SysEmissionStandardTotalInfo) MapUtils.convertMap(SysEmissionStandardTotalInfo.class,payload);
            SysEmissionStandardTotalInfo = sysEmissionStandardTotalInfoRepository.save(SysEmissionStandardTotalInfo1);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return SysEmissionStandardTotalInfo;
    }


    /**
     *
     * 根据id查询排放标准总则
     *
     * @param id
     * @return
     */
    public SysEmissionStandardTotalInfo findId(String id){
        SysEmissionStandardTotalInfo SysEmissionStandardTotalInfo = null;
        try {
            SysEmissionStandardTotalInfo = sysEmissionStandardTotalInfoRepository.findSysEmissionStandardTotalInfoById(id);
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return SysEmissionStandardTotalInfo;
    }

    /**
     *
     * 根据id 删除排放标准总则
     *
     * @param id
     */
    public Boolean delete(String id) {
        Boolean result = false;
        try {
            Integer result1 = sysEmissionStandardTotalInfoRepository.deleteById(id);
            if(result1 == 1){
                result = true;
            }
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return result;
    }

    /**
     *查询所有排放标准总则
     *
     * @return List<SysEmissionStandardTotalInfo>
     */
    public List<SysEmissionStandardTotalInfo> findAll() {
        List<SysEmissionStandardTotalInfo> SysEmissionStandardTotalInfos = null;
        try {
            SysEmissionStandardTotalInfos =  sysEmissionStandardTotalInfoRepository.findAll();
        }catch (Exception e){
            logger.error(e.getLocalizedMessage());
        }
        return SysEmissionStandardTotalInfos;
    }

}
